﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using rbac.share;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace rbac.services
{
    public class ServiceBase
    {
        protected readonly IMapper _mapper;

        protected IHttpContextAccessor _contextAccessor;

        protected int loginuserids;

        public ServiceBase()
        {
            // 从容器中获取服务实例
            _mapper = ServiceProviderLocator.Instance.GetService<IMapper>()!;
            _contextAccessor = ServiceProviderLocator.Instance.GetService<IHttpContextAccessor>()!;
            // 判断一下是否被授权了
            if (_contextAccessor.HttpContext != null)
            {
                if (_contextAccessor.HttpContext.User.Identity!.IsAuthenticated)
                {
                    loginuserids = Convert.ToInt32(_contextAccessor.HttpContext.User.Claims
                        .FirstOrDefault(p => p.Type.Equals("UserId")).Value);
                }
            }
        }


    }
}
